# 文件操作模块有以下功能(写在类里面的函数)：读取文件内容 写入内容到文件中 复制文件 删除文件 文件改名
import os


class File_operations:

    @staticmethod
    def read(filename):
        # 打开文件
        f = open(f'{filename}', 'r', encoding='utf8')
        #操作文件
        content = f.read()
        #关闭文件
        f.close()
        print(content)

    @staticmethod
    def write(filename, content):
        #打开文件
        f = open(f'{filename}', 'a', encoding='utf8')
        # 操作文件
        f.write(content + '\n')
        #关闭文件
        f.close()
        print(content)

    @staticmethod
    def copy():
        filename = input('请输入文件名:')
        source_filename, extend = os.path.splitext(filename)
        new_filename = source_filename + '-副本' + extend
        f = open(f'{filename}', 'r', encoding='utf8')
        content = f.read()
        f.close()
        f = open(new_filename, 'a', encoding='utf8')
        f.write(content)
        f.close()

    @staticmethod
    def remove(newfilename):
        os.remove(newfilename)

    @staticmethod
    def alter(filename, newfilename):
        os.rename(filename, newfilename)
File_operations.read('happy.txt')
File_operations.write('Happy.txt', '你好武汉')
File_operations.copy()
File_operations.remove('happy-副本.txt')
File_operations.alter('happy.txt', 'hahaha.txt')






